<?php
include_once "xAP-functions/webincludes.php";

$extradata["sourceid"]=intval($_GET["id"]);

$now=date("Y-m-d H:i:s");

if(intval($extradata["sourceid"])>0){
	// just one source
	$sql="select * from xAP_Weather_Source
	where Active=1 and SourceID=".intval($extradata["sourceid"])."
	";
	$results=dbquery($sql);
	$title=$results[0]["Location"];
}
else
{
	// all sources
	$sql="select * from xAP_Weather_Source
	where Active=1
	order by Location
	";
	$results=dbquery($sql);
	$title="Current Weather";
}


//display
$body= "<Table class='widget'>";
foreach($results as $row){
	$sunrise=date_sunrise(time(),SUNFUNCS_RET_STRING,$row["lat"],$row["lng"],$zenith,1);
	$sunset=date_sunset(time(),SUNFUNCS_RET_STRING,$row["lat"],$row["lng"],$zenith,-1);
	//day or night
	$timeofday="night";
	$iconprefix="night";
	if(strtotime($sunrise)<strtotime($now) && strtotime($sunset)>strtotime($now)){
			$timeofday="day";
			$iconprefix="";
	}	
	$body.= "<tr>
	<TD width=33><a href='/".$config["modulefolder"]."/index.php'>
	<img src='/".$config["modulefolder"]."/images/".$iconprefix.$row["Icon"].".jpg' height=32 width=32></a></td>
	<TD>
	<span class='boldsmalltext'>".$row["Location"]."</span><BR>
	<span class='normalsmalltext'>".$row["Temp"]."&deg;C ".$row["WindSpeed"]."mph ".$row["WindDirection"]." ".$row["Pressure"]."mB ".$row["Humidity"]."%</span>
	</td>
	</tr>
	";

}
$body.= "</table>";
echo $body;
?>